package com.zhima.service;

import com.zhima.dto.AuthParamsDTO;
import com.zhima.dto.CreateOjUserDTO;
import com.zhima.dto.UserDTOExtension;
import com.zhima.feignclient.UserFeignClient;
import org.springframework.security.crypto.password.PasswordEncoder;

import static com.zhima.constant.UserConstant.*;

public interface AuthService {

    /**
     * 根据认证参数认证
     * 返回值需要带有权限列表
     *
     * @param authParamsDTO
     * @return
     */
    UserDTOExtension auth(AuthParamsDTO authParamsDTO);

    default UserDTOExtension createPlainUser(CreateOjUserDTO ojUser, PasswordEncoder passwordEncoder, UserFeignClient userFeignClient) {
        ojUser.setUserName(generateRandomUserName());
        ojUser.setPassword(passwordEncoder.encode(DEFAULT_PASSWORD));
        ojUser.setAvatarUri(DEFAULT_AVATAR);
        ojUser.setIntroduction(DEFAULT_INTRODUCTION);
        return userFeignClient.createPlainUser(ojUser);
    }
}
